package com.briup.srms.sms.web.controller;

import java.util.List;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.srms.sms.bean.Department;
import com.briup.srms.sms.bean.extend.DepartmentExtend;
import com.briup.srms.sms.service.IDepartmentService;
import com.jacky.base.utils.Message;
import com.jacky.base.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @program: 杰普基础管理系统
 * @description: 部门管理的控制器类
 * @author: charles
 * @create: 2020-11-14 15:09
 **/
@Api(description="部门相关接口")
@Validated
@RestController
@RequestMapping("/dept")
public class DepartmentController {

	@Autowired
	private IDepartmentService departmentService;

	@ApiOperation(value = "查询部门树")
    @GetMapping("queryTree")
    public Message queryTree(){
		List<DepartmentExtend> list = departmentService.queryTree();
        return MessageUtil.success(list);
    }

	@ApiOperation(value = "保存或更新")
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Department department){
		departmentService.saveOrUpdate(department);
        return MessageUtil.success("操作成功");
    }

	@ApiOperation(value = "根据ID删除")
    @GetMapping("deleteById")
    public Message deleteById(@NotNull long id){
		departmentService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

}
